package com.ruoyi.project.labapprove.service;

import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.lab.domain.LabAppointmentDto;
import com.ruoyi.project.labapprove.domain.ApproveParam;
import com.ruoyi.project.labapprove.mapper.LabApproveMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class LabApproveServiceImpl implements LabApproveService{

    @Autowired
    private LabApproveMapper labApproveMapper;

    @Override
    public List<LabAppointmentDto> selectList(ApproveParam approveParam) {
        return labApproveMapper.selectList(approveParam);
    }

    @Override
    public AjaxResult audit(Long id) {
        int result=labApproveMapper.audit(id);
        if(result>0){
            return new AjaxResult(AjaxResult.Type.SUCCESS,"审核成功");
        }else {
            return new AjaxResult(AjaxResult.Type.ERROR,"审核失败");
        }
    }

    @Override
    @Transactional
    public AjaxResult auditRefuse(Long id) {
        int result=labApproveMapper.auditRefuse(id);
        //审核失败修改实验室状态
        Long labDateId=labApproveMapper.selectlabDateId(id);
        labApproveMapper.updateLabDateStatus(labDateId);
        if(result>0){
            return new AjaxResult(AjaxResult.Type.SUCCESS,"审核成功");
        }else {
            return new AjaxResult(AjaxResult.Type.ERROR,"审核失败");
        }
    }
}
